package com.sa07.ui.config;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;

import com.sa07.config.XmlConfigInit;
import com.sa07.ui.bean.ConfigConstTag;
import com.sa07.ui.bean.StatuslItem;

/**
 * 状态栏配置初始化
 * 
 * @author Long.shangbo
 * 
 *         2014-2-15 上午1:22:30
 */
public class StatusBarConfigInit extends XmlConfigInit {

	/**
	 * 状态栏配置文件
	 */
	private static final String STATUS_BAR_CONFIG_FILE = "statusbar.xml";

	@Override
	protected InputStream getConfigInputStream() {
		return StatusBarConfigInit.class
				.getResourceAsStream(STATUS_BAR_CONFIG_FILE);
	}

	@Override
	protected void analyzeDocment(Document doc) {
		Element rootEle = doc.getRootElement();

		if (rootEle != null) {
			List<Element> statusItemEles = rootEle
					.getChildren(ConfigConstTag.STATUS_ITEM_TAG);

			if (statusItemEles != null && !statusItemEles.isEmpty()) {
				List<StatuslItem> statusItems = new ArrayList<StatuslItem>();
				StatuslItem statusItem = null;

				for (Element statusItemEle : statusItemEles) {
					if (statusItemEle != null) {
						statusItem = new StatuslItem();
						statusItem.setName(statusItemEle.getAttributeValue(ConfigConstTag.NAME_ATTR));
						statusItem.setLabel(statusItemEle.getAttributeValue(ConfigConstTag.LABEL_ATTR));
						statusItem.setHandlerClass(statusItemEle.getAttributeValue(ConfigConstTag.HANDLER_CLASS_ATTR));
						statusItem.setDisabled(statusItemEle.getAttributeValue(ConfigConstTag.DISABLED_ATTR));
						statusItems.add(statusItem);
					}
				}
				// 初始化
				StatusBarConfig.INSTANCE.init(statusItems);
			}
		}
	}

}
